package gui;

import houseHold.House;

import java.awt.Dimension;

import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.border.BevelBorder;

public class ObjectListPopupMenu {
	private JMenuItem RemoveObject;
	private String roomName, itemName;
	private JPopupMenu RoomPopUp;
	private int type = -1;

	public ObjectListPopupMenu(String ItemName, String RoomName, int type) {
		this.itemName = ItemName;
		this.roomName = RoomName;
		this.type = type;
	}

	/**
	 * This method initializes AddObject
	 * 
	 * @return javax.swing.JMenuItem
	 */
	private JMenuItem getRemoveObject(final RoomInformationDialog RD) {
		if (RemoveObject == null) {
			RemoveObject = new JMenuItem();
			RemoveObject.setText("Remove " + itemName);
			RemoveObject.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					switch (type) {
					case 0: {
						House.getInstance().getRoom(roomName).removeItem(
								itemName);
						RD.populateLists();
						break;
					}
					case 1: {
						House.getInstance().getRoom(roomName).removeSensor(
								itemName);
						RD.populateLists();
						break;
					}
					}
				}
			});
		}
		return RemoveObject;
	}

	public JPopupMenu getRoomPopUp(RoomInformationDialog RD) {
		if (RoomPopUp == null) {
			RoomPopUp = new JPopupMenu();
			RoomPopUp.setSize(new Dimension(80, 120));
			RoomPopUp.add(getRemoveObject(RD));
			RoomPopUp.setBorder(new BevelBorder(BevelBorder.RAISED));

		}
		return RoomPopUp;
	}

}
